<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>

<div class="form-group">
<div class="container-fluid" >
	<div class="row" id="groupsBox"></div>	
</div>
</div>
<button type="button" id="submitMyGroupBtn">提交</button>
<script type="text/javascript">
$(function(){
	var groupsBox=$("#groupsBox");
	$.getJSON(ctx+"/userGroupAct/loadGroups.do",function(gs){
		$.each(gs,function(gi,gn){
			groupsBox.append("<div class='col-md-3'><input type='checkbox' name='groupBox' value='"+gn.id+"'>"+gn.title+"</input></div>");
		});
		$.getJSON(ctx+"/userGroupAct/loadUserGroups.do",function(ugs){
			$.each(ugs,function(ugi,ugn){
				groupsBox.find("input[value='"+ugn.id+"']").attr("checked",true);
			});
		});
	});
	
	$("#submitMyGroupBtn").click(function(){
		var groupIds=[];
		$("#groupsBox input[name='groupBox']:checked").each(function(i,n){
			groupIds.push($(n).val());
		});
		$.post(ctx+"/userGroupAct/saveUserGroup.do",{groupIds:groupIds.join(",")},function(i,n){
			webUtils.fire("userGroup.save.success");
		},"json");
	});
});
</script>